import { Controller, Get, Post, Body, Patch, Param, Delete, Query, UseGuards } from '@nestjs/common'
import { CommentService } from './comment.service'
import { CreateCommentDto } from './dto/create-comment.dto'
import { UpdateCommentDto } from './dto/update-comment.dto'
import { AuthGuard } from '@nestjs/passport';

@Controller('comment')
@UseGuards(AuthGuard('jwt'))
export class CommentController {
    constructor(private readonly commentService: CommentService) { }

    @Post()
    create(@Body() createCommentDto: CreateCommentDto) {
        return this.commentService.create(createCommentDto);
    }

    @Get()
    findAll(@Query() urlQuery: { status?: string, articleId?: string, pageIndex: string, pageSize: string }) {
        const query = {
            status: urlQuery.status ? +urlQuery.status : undefined,
            articleId: urlQuery.articleId ? +urlQuery.articleId : undefined,
            pageIndex: +urlQuery.pageIndex,
            pageSize: +urlQuery.pageSize
        }
        return this.commentService.findAll(query);
    }

    @Get(':id')
    findOne(@Param('id') id: string) {
        return this.commentService.findOne(+id);
    }

    @Patch(':id')
    update(@Param('id') id: string, @Body() updateCommentDto: UpdateCommentDto) {
        return this.commentService.update(+id, updateCommentDto);
    }

    @Delete(':id')
    remove(@Param('id') id: string) {
        return this.commentService.remove(+id);
    }
}
